<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><title>从零实现Vue3.x-工程&amp;架构篇 | Pluto</title><meta name="author" content="拾壹baby"><meta name="copyright" content="拾壹baby"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="前言温故而知新，虽然 vue3.x 已经发布很久了，但对于源码的分析总能让我们每次都有收获，因此决定写一个 vue3.x 的源码分析的系列文章，vue 版本是 3.2.26。主要从以下几个方面展开分析：  工程&amp;架构 响应式系统 渲染器 &amp; diff 算法 内置组件  目录划分： 采用 monorepo 架构，做到了模块的统一管理与单独发布，相比于vue2.x尽可能的做到了模块之间">
<meta property="og:type" content="article">
<meta property="og:title" content="从零实现Vue3.x-工程&amp;架构篇">
<meta property="og:url" content="http://cdn.pluto1811.com/pluto/2022/08/10/vue3-01/">
<meta property="og:site_name" content="Pluto">
<meta property="og:description" content="前言温故而知新，虽然 vue3.x 已经发布很久了，但对于源码的分析总能让我们每次都有收获，因此决定写一个 vue3.x 的源码分析的系列文章，vue 版本是 3.2.26。主要从以下几个方面展开分析：  工程&amp;架构 响应式系统 渲染器 &amp; diff 算法 内置组件  目录划分： 采用 monorepo 架构，做到了模块的统一管理与单独发布，相比于vue2.x尽可能的做到了模块之间">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="http://cdn.pluto1811.com/goodsImage/1654484986665/1654484958862.jpg">
<meta property="article:published_time" content="2022-08-10T05:20:55.000Z">
<meta property="article:modified_time" content="2022-11-12T03:24:56.128Z">
<meta property="article:author" content="拾壹baby">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="http://cdn.pluto1811.com/goodsImage/1654484986665/1654484958862.jpg"><link rel="shortcut icon" href="/pluto/img/favicon.png"><link rel="canonical" href="http://cdn.pluto1811.com/pluto/2022/08/10/vue3-01/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/pluto/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/pluto/',
  algolia: undefined,
  localSearch: undefined,
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isAnchor: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: '从零实现Vue3.x-工程&架构篇',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2022-11-12 11:24:56'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><meta name="generator" content="Hexo 6.3.0"><link rel="alternate" href="/pluto/atom.xml" title="Pluto" type="application/atom+xml">
</head><body><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="https://i.loli.net/2021/02/24/5O1day2nriDzjSu.png" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/pluto/archives/"><div class="headline">文章</div><div class="length-num">22</div></a><a href="/pluto/tags/"><div class="headline">标签</div><div class="length-num">0</div></a><a href="/pluto/categories/"><div class="headline">分类</div><div class="length-num">0</div></a></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/pluto/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/pluto/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/pluto/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/pluto/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/pluto/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('http://cdn.pluto1811.com/goodsImage/1654484986665/1654484958862.jpg')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/pluto/">Pluto</a></span><div id="menus"><div class="menus_items"><div class="menus_item"><a class="site-page" href="/pluto/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/pluto/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/pluto/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/pluto/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/pluto/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">从零实现Vue3.x-工程&amp;架构篇</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2022-08-10T05:20:55.000Z" title="发表于 2022-08-10 13:20:55">2022-08-10</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2022-11-12T03:24:56.128Z" title="更新于 2022-11-12 11:24:56">2022-11-12</time></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="从零实现Vue3.x-工程&amp;架构篇"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h3 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h3><p>温故而知新，虽然 vue3.x 已经发布很久了，但对于源码的分析总能让我们每次都有收获，因此决定写一个 vue3.x 的源码分析的系列文章，vue 版本是 3.2.26。主要从以下几个方面展开分析：</p>
<ol>
<li>工程&amp;架构</li>
<li>响应式系统</li>
<li>渲染器 &amp; diff 算法</li>
<li>内置组件</li>
</ol>
<h3 id="目录划分："><a href="#目录划分：" class="headerlink" title="目录划分："></a>目录划分：</h3><img src="http://cdn.pluto1811.com/1654418177792.jpg">
采用 monorepo 架构，做到了模块的统一管理与单独发布，相比于vue2.x尽可能的做到了模块之间的解耦.

<h4 id="项目的起点：package-json"><a href="#项目的起点：package-json" class="headerlink" title="项目的起点：package.json"></a>项目的起点：package.json</h4><ol>
<li>npm 的钩子函数</li>
</ol>
<pre class="line-numbers language-json" data-language="json"><code class="language-json"><span class="token punctuation">&#123;</span>
  <span class="token property">"private"</span><span class="token operator">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span>
  <span class="token property">"version"</span><span class="token operator">:</span> <span class="token string">"3.2.22"</span><span class="token punctuation">,</span>
  <span class="token property">"scripts"</span><span class="token operator">:</span> <span class="token punctuation">&#123;</span>
    <span class="token property">"preinstall"</span><span class="token operator">:</span> <span class="token string">"node ./scripts/preinstall.js"</span><span class="token punctuation">,</span>
  <span class="token punctuation">&#125;</span>
<span class="token punctuation">&#125;</span>
<span class="token comment">// 相关的钩子：依次执行</span>
# install 之前执行这个脚本
preinstall
# 执行 install 脚本
install
# install 之后执行这个脚本
postinstall<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>

<ol start="2">
<li>代码风格检查与提交规范</li>
</ol>
<pre class="line-numbers language-json" data-language="json"><code class="language-json"><span class="token property">"gitHooks"</span><span class="token operator">:</span> <span class="token punctuation">&#123;</span>
  <span class="token property">"pre-commit"</span><span class="token operator">:</span> <span class="token string">"lint-staged"</span><span class="token punctuation">,</span>
  <span class="token property">"commit-msg"</span><span class="token operator">:</span> <span class="token string">"node scripts/verifyCommit.js"</span>
<span class="token punctuation">&#125;</span><span class="token punctuation">,</span>
<span class="token property">"lint-staged"</span><span class="token operator">:</span> <span class="token punctuation">&#123;</span>
  <span class="token property">"*.js"</span><span class="token operator">:</span> <span class="token punctuation">[</span>
    <span class="token string">"prettier --write"</span>
  <span class="token punctuation">]</span><span class="token punctuation">,</span>
  <span class="token property">"*.ts?(x)"</span><span class="token operator">:</span> <span class="token punctuation">[</span>
    <span class="token string">"eslint"</span><span class="token punctuation">,</span>
    <span class="token string">"prettier --parser=typescript --write"</span>
  <span class="token punctuation">]</span>
<span class="token punctuation">&#125;</span><span class="token punctuation">,</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>

<ol start="3">
<li>workspace:*</li>
</ol>
<pre class="line-numbers language-json" data-language="json"><code class="language-json"><span class="token property">"@vue/reactivity"</span><span class="token operator">:</span> <span class="token string">"workspace:*"</span><span class="token punctuation">,</span>
<span class="token property">"@vue/runtime-core"</span><span class="token operator">:</span> <span class="token string">"workspace:*"</span><span class="token punctuation">,</span>
<span class="token property">"@vue/runtime-dom"</span><span class="token operator">:</span> <span class="token string">"workspace:*"</span><span class="token punctuation">,</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span></span></code></pre>

<p>在 pnpm 模式下 package.json 有一种特殊的写法：”workspace:*“，为了指明这是工作区的依赖，防止自动去 npm 上寻找导致混乱，当使用此协议时，pnpm 将拒绝解析除本地 workspace 包含的 package 之外的任何内容。</p>
<p>例如，如果 bar 中有 “foo”：”^1.0.0” 的这个依赖项，则 <a href="mailto:&#x66;&#111;&#x6f;&#64;&#x31;&#x2e;&#x30;&#x2e;&#48;">&#x66;&#111;&#x6f;&#64;&#x31;&#x2e;&#x30;&#x2e;&#48;</a> 链接到 bar。 但是，如果 bar 的依赖项中有 “foo”: “2.0.0”，而 <a href="mailto:&#102;&#x6f;&#x6f;&#64;&#50;&#46;&#x30;&#x2e;&#x30;">&#102;&#x6f;&#x6f;&#64;&#50;&#46;&#x30;&#x2e;&#x30;</a> 在工作空间中并不存在，此时会从 npm registry 上安装<a href="mailto:&#102;&#111;&#111;&#x40;&#x32;&#x2e;&#x30;&#x2e;&#48;">&#102;&#111;&#111;&#x40;&#x32;&#x2e;&#x30;&#x2e;&#48;</a>，如果设置为 “foo”: “workspace:2.0.0” 时，安装将会失败，因为 “<a href="mailto:&#x66;&#111;&#x6f;&#64;&#x32;&#x2e;&#48;&#46;&#x30;">&#x66;&#111;&#x6f;&#64;&#x32;&#x2e;&#48;&#46;&#x30;</a>“ 不存在于此 workspace 中</p>
<ol start="4">
<li>packages 中每个模块中都有一个 json 文件</li>
</ol>
<p>这个文件主要是与<a target="_blank" rel="noopener" href="https://www.npmjs.com/package/@microsoft/api-extractor">@microsoft&#x2F;api-extractor</a>这个插件配合使用</p>
<ul>
<li><p>可以产生三种不同的输出类型:</p>
</li>
<li><p>API Report —API Extractor 可以跟踪项目主入口点的所有导出，并生成一个报告作为 API 审查工作流的基础。</p>
</li>
<li><p>.d.ts Rollups—类似于 Webpack 可以将所有 JavaScript 文件“卷起”到一个包中进行分发，API Extractor 可以将你的 TypeScript 声明卷成一个单独的.d。ts 文件。</p>
</li>
<li><p>API Documentation—API Extractor 可以为每个项目生成“doc model”JSON 文件。这个 JSON 文件包含提取的类型签名和文档注释。API -documenter 配套工具可以使用这些文件生成 API 参考网站，也可以使用它们作为自定义文档管道的输入。</p>
</li>
</ul>
<p>这是为了指明这是工作区的依赖，防止自动去 npm 上寻找导致混乱。当使用此协议时，pnpm 将拒绝解析除本地 workspace 包含的 package 之外的任何内容。</p>
<h4 id="为什么是-pnpm？"><a href="#为什么是-pnpm？" class="headerlink" title="为什么是 pnpm？"></a>为什么是 pnpm？</h4><p>pnpm 是一个包管理器，本质上与 npm&#x2F;yarn 是一样的，但它却有几个优势：</p>
<ol>
<li>依赖安装速度极快；</li>
<li>磁盘空间利用高；<br>同一个包不会重复安装，比如 10 个项目都依赖了 lodash，在 npm&#x2F;yarn 中，lodash 可能会被安装 10 次；极大程度地复用之前版本的代码，</li>
<li>天然支持 monorepo<br>只需要在项目更目录新增一个 pnpm-workspace.yaml</li>
</ol>
<pre class="line-numbers language-text" data-language="text"><code class="language-text">packages:
  - 'packages/*'<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span></span></code></pre>

<ol start="4">
<li>避免依赖包的非法访问<br>比如在 a 包中依赖了 lodash，那么我们在项目的 package.json 文件中不用显式的声明 lodash 依赖；这样不是很好吗？但我们考虑一下场景：<br>如果有天 a 包中移除了 lodash 依赖，那么可能会导致我们自己的项目异常；</li>
</ol>
<h4 id="开发语言：摈弃-flow，全面采用-ts"><a href="#开发语言：摈弃-flow，全面采用-ts" class="headerlink" title="开发语言：摈弃 flow，全面采用 ts"></a>开发语言：摈弃 flow，全面采用 ts</h4><p>在 vue2.x 时代，尤大更中意的是 Facebook（现在应该叫 Meta 了）开源的 flow，但没想到 flow 最后烂尾了，而 typescript 生态则越来越丰富，其他的正如<a target="_blank" rel="noopener" href="https://vuejs.org/guide/typescript/overview.html" >Vue 官方说的</a>：<br>构建时通过静态分析检测许多常见错误。这减少了生产中出现运行时错误的机会，也使我们能够更自信地重构大规模应用程序中的代码。TypeScript 还通过 ide 中基于类型的自动补全改进了开发者的体验。</p>
<h4 id="开发环境采用-esbuild-构建代码"><a href="#开发环境采用-esbuild-构建代码" class="headerlink" title="开发环境采用 esbuild 构建代码"></a>开发环境采用 esbuild 构建代码</h4><p>Esbuild 是由 Figma 的 CTO 「Evan Wallace」基于 Golang 开发的一款打包工具，相比传统的打包工具，主打性能优势，在构建速度上可以快 10~100 倍。</p>
<pre class="line-numbers language-javascript" data-language="javascript"><code class="language-javascript"><span class="token function">build</span><span class="token punctuation">(</span><span class="token punctuation">&#123;</span>
  <span class="token literal-property property">entryPoints</span><span class="token operator">:</span> <span class="token punctuation">[</span><span class="token function">resolve</span><span class="token punctuation">(</span>__dirname<span class="token punctuation">,</span> <span class="token template-string"><span class="token template-punctuation string">`</span><span class="token string">../packages/</span><span class="token interpolation"><span class="token interpolation-punctuation punctuation">$&#123;</span>target<span class="token interpolation-punctuation punctuation">&#125;</span></span><span class="token string">/src/index.ts</span><span class="token template-punctuation string">`</span></span><span class="token punctuation">)</span><span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token comment">// 入口文件</span>
  outfile<span class="token punctuation">,</span> <span class="token comment">// 打包生成的产物路径</span>
  <span class="token literal-property property">bundle</span><span class="token operator">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span>
  external<span class="token punctuation">,</span>
  <span class="token literal-property property">sourcemap</span><span class="token operator">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span> <span class="token comment">// 开启sourcemap</span>
  <span class="token literal-property property">format</span><span class="token operator">:</span> outputFormat<span class="token punctuation">,</span> <span class="token comment">// 生成产物的格式 目前支持 iife 自执行函数、cjs 主要是node环境、esm 以es6语法产出 支持 &lt;script type="mudule"></span>
  <span class="token literal-property property">globalName</span><span class="token operator">:</span> pkg<span class="token punctuation">.</span>buildOptions<span class="token operator">?.</span>name<span class="token punctuation">,</span> <span class="token comment">// 自执行函数的全局名</span>
  <span class="token literal-property property">platform</span><span class="token operator">:</span> format <span class="token operator">===</span> <span class="token string">'cjs'</span> <span class="token operator">?</span> <span class="token string">'node'</span> <span class="token operator">:</span> <span class="token string">'browser'</span><span class="token punctuation">,</span> <span class="token comment">// 针对的平台</span>
  <span class="token literal-property property">plugins</span><span class="token operator">:</span>
    format <span class="token operator">===</span> <span class="token string">'cjs'</span> <span class="token operator">||</span> pkg<span class="token punctuation">.</span>buildOptions<span class="token operator">?.</span>enableNonBrowserBranches
      <span class="token operator">?</span> <span class="token punctuation">[</span>nodePolyfills<span class="token punctuation">.</span><span class="token function">default</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">]</span>
      <span class="token operator">:</span> <span class="token keyword">undefined</span><span class="token punctuation">,</span>
  <span class="token literal-property property">define</span><span class="token operator">:</span> <span class="token punctuation">&#123;</span> <span class="token comment">// 全局变量 类似于 webpack.defineplugin</span>
    <span class="token literal-property property">__COMMIT__</span><span class="token operator">:</span> <span class="token template-string"><span class="token template-punctuation string">`</span><span class="token string">"dev"</span><span class="token template-punctuation string">`</span></span><span class="token punctuation">,</span>
    <span class="token literal-property property">__VERSION__</span><span class="token operator">:</span> <span class="token template-string"><span class="token template-punctuation string">`</span><span class="token string">"</span><span class="token interpolation"><span class="token interpolation-punctuation punctuation">$&#123;</span>pkg<span class="token punctuation">.</span>version<span class="token interpolation-punctuation punctuation">&#125;</span></span><span class="token string">"</span><span class="token template-punctuation string">`</span></span><span class="token punctuation">,</span>
    <span class="token literal-property property">__DEV__</span><span class="token operator">:</span> <span class="token template-string"><span class="token template-punctuation string">`</span><span class="token string">true</span><span class="token template-punctuation string">`</span></span><span class="token punctuation">,</span>
    <span class="token operator">...</span>
  <span class="token punctuation">&#125;</span><span class="token punctuation">,</span>
  <span class="token literal-property property">watch</span><span class="token operator">:</span> <span class="token punctuation">&#123;</span> <span class="token comment">// 文件变动的监听函数</span>
    <span class="token function">onRebuild</span><span class="token punctuation">(</span><span class="token parameter">error</span><span class="token punctuation">)</span> <span class="token punctuation">&#123;</span>
      <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token operator">!</span>error<span class="token punctuation">)</span> console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token template-string"><span class="token template-punctuation string">`</span><span class="token string">rebuilt: </span><span class="token interpolation"><span class="token interpolation-punctuation punctuation">$&#123;</span>relativeOutfile<span class="token interpolation-punctuation punctuation">&#125;</span></span><span class="token template-punctuation string">`</span></span><span class="token punctuation">)</span>
    <span class="token punctuation">&#125;</span>
  <span class="token punctuation">&#125;</span>
<span class="token punctuation">&#125;</span><span class="token punctuation">)</span>
<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="http://cdn.pluto1811.com/pluto">拾壹baby</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="http://cdn.pluto1811.com/pluto/2022/08/10/vue3-01/">http://cdn.pluto1811.com/pluto/2022/08/10/vue3-01/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="http://cdn.pluto1811.com/pluto" target="_blank">Pluto</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"></div><div class="post_share"><div class="social-share" data-image="http://cdn.pluto1811.com/goodsImage/1654484986665/1654484958862.jpg" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/pluto/2022/08/10/jest/"><img class="prev-cover" src="http://cdn.pluto1811.com/goodsImage/1619772970467/1619772941918.jpg" onerror="onerror=null;src='/pluto/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">关于jest的TDD与BDD开发模式</div></div></a></div><div class="next-post pull-right"><a href="/pluto/2022/08/06/vue3-04/"><img class="next-cover" src="http://cdn.pluto1811.com/goodsImage/1654586549371/1654586481783.jpg" onerror="onerror=null;src='/pluto/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">从零实现vue3.x-ref、computed、watch的实现</div></div></a></div></nav></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="https://i.loli.net/2021/02/24/5O1day2nriDzjSu.png" onerror="this.onerror=null;this.src='/pluto/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">拾壹baby</div><div class="author-info__description">个人博客</div></div><div class="card-info-data site-data is-center"><a href="/pluto/archives/"><div class="headline">文章</div><div class="length-num">22</div></a><a href="/pluto/tags/"><div class="headline">标签</div><div class="length-num">0</div></a><a href="/pluto/categories/"><div class="headline">分类</div><div class="length-num">0</div></a></div><a id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/xxxxxx"><i class="fab fa-github"></i><span>Follow Me</span></a></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>公告</span></div><div class="announcement_content">This is my Blog</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%89%8D%E8%A8%80"><span class="toc-number">1.</span> <span class="toc-text">前言</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%9B%AE%E5%BD%95%E5%88%92%E5%88%86%EF%BC%9A"><span class="toc-number">2.</span> <span class="toc-text">目录划分：</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E9%A1%B9%E7%9B%AE%E7%9A%84%E8%B5%B7%E7%82%B9%EF%BC%9Apackage-json"><span class="toc-number">2.1.</span> <span class="toc-text">项目的起点：package.json</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E4%B8%BA%E4%BB%80%E4%B9%88%E6%98%AF-pnpm%EF%BC%9F"><span class="toc-number">2.2.</span> <span class="toc-text">为什么是 pnpm？</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%BC%80%E5%8F%91%E8%AF%AD%E8%A8%80%EF%BC%9A%E6%91%88%E5%BC%83-flow%EF%BC%8C%E5%85%A8%E9%9D%A2%E9%87%87%E7%94%A8-ts"><span class="toc-number">2.3.</span> <span class="toc-text">开发语言：摈弃 flow，全面采用 ts</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%BC%80%E5%8F%91%E7%8E%AF%E5%A2%83%E9%87%87%E7%94%A8-esbuild-%E6%9E%84%E5%BB%BA%E4%BB%A3%E7%A0%81"><span class="toc-number">2.4.</span> <span class="toc-text">开发环境采用 esbuild 构建代码</span></a></li></ol></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/pluto/2022/10/25/me2022-10/" title="嗯，这两三年...2022年中总结"><img src="http://cdn.pluto1811.com/goodsImage/1650448154299/1650448126499.jpg" onerror="this.onerror=null;this.src='/pluto/img/404.jpg'" alt="嗯，这两三年...2022年中总结"/></a><div class="content"><a class="title" href="/pluto/2022/10/25/me2022-10/" title="嗯，这两三年...2022年中总结">嗯，这两三年...2022年中总结</a><time datetime="2022-10-25T05:20:55.000Z" title="发表于 2022-10-25 13:20:55">2022-10-25</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/pluto/2022/10/25/promise/" title="Promise里的代码为什么比setTimeout先执行？"><img src="http://cdn.pluto1811.com/goodsImage/1615188358809/376997778.jpg" onerror="this.onerror=null;this.src='/pluto/img/404.jpg'" alt="Promise里的代码为什么比setTimeout先执行？"/></a><div class="content"><a class="title" href="/pluto/2022/10/25/promise/" title="Promise里的代码为什么比setTimeout先执行？">Promise里的代码为什么比setTimeout先执行？</a><time datetime="2022-10-25T05:20:55.000Z" title="发表于 2022-10-25 13:20:55">2022-10-25</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/pluto/2022/10/23/jsobject/" title="JavaScript对象：啥？对象还有分类？"><img src="http://cdn.pluto1811.com/goodsImage/1615184906664/374751567.jpg" onerror="this.onerror=null;this.src='/pluto/img/404.jpg'" alt="JavaScript对象：啥？对象还有分类？"/></a><div class="content"><a class="title" href="/pluto/2022/10/23/jsobject/" title="JavaScript对象：啥？对象还有分类？">JavaScript对象：啥？对象还有分类？</a><time datetime="2022-10-23T05:20:55.000Z" title="发表于 2022-10-23 13:20:55">2022-10-23</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/pluto/2022/10/19/hexo-ci/" title="【超实用】完美实现基于hexo的博客网站自动化部署"><img src="http://cdn.pluto1811.com/20221020140348.png" onerror="this.onerror=null;this.src='/pluto/img/404.jpg'" alt="【超实用】完美实现基于hexo的博客网站自动化部署"/></a><div class="content"><a class="title" href="/pluto/2022/10/19/hexo-ci/" title="【超实用】完美实现基于hexo的博客网站自动化部署">【超实用】完美实现基于hexo的博客网站自动化部署</a><time datetime="2022-10-19T06:20:58.000Z" title="发表于 2022-10-19 14:20:58">2022-10-19</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/pluto/2022/10/16/jstyping/" title="JavaScript类型，有可能你不知道这些细节"><img src="http://cdn.pluto1811.com/20221020140348.png" onerror="this.onerror=null;this.src='/pluto/img/404.jpg'" alt="JavaScript类型，有可能你不知道这些细节"/></a><div class="content"><a class="title" href="/pluto/2022/10/16/jstyping/" title="JavaScript类型，有可能你不知道这些细节">JavaScript类型，有可能你不知道这些细节</a><time datetime="2022-10-16T05:20:55.000Z" title="发表于 2022-10-16 13:20:55">2022-10-16</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2023 By 拾壹baby</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/pluto/js/utils.js"></script><script src="/pluto/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.umd.min.js"></script><div class="js-pjax"></div><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div></body></html>